package com.snooker.snooker.service.impl;

import com.snooker.snooker.dao.EventMapper;
import com.snooker.snooker.dao.GameForEventMapper;
import com.snooker.snooker.dto.EventDto;
import com.snooker.snooker.dto.GameForEventDto;
import com.snooker.snooker.entity.Event;
import com.snooker.snooker.service.EventService;
import com.snooker.snooker.util.DataFormatUtil;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Description: 赛季比赛相关serviceimpl
 * @Param:
 * @return:
 * @Author: fenghouzhi
 * @Date: 1:49 PM 2018/11/6
 */
@Slf4j
@Service
public class EventServiceImpl implements EventService {

  @Resource
  private EventMapper eventMapper;

  @Resource
  private GameForEventMapper gameForEventMapper;


  /**
   * 获取本赛季的所有比赛信息
   */
  @Override
  public List<Event> getAllEvent(Integer season) {
    return eventMapper.getAllEvent(season);
  }

  @Override
  public List<EventDto> getAllEventDto(Integer season) {
    return eventMapper.getAllEventDto(season);
  }

  /**
   * 获取本赛季所有的比赛ID
   */
  @Override
  public List<Integer> getAllEventId(Integer season) {
    return eventMapper.getAllEventId(season);
  }

  /**
   * 获取本赛季单站比赛的信息以及轮次的信息
   */
  @Override
  public EventDto getEventDtoByEventId(Integer eventId) {

    EventDto eventDto = eventMapper.getEventDtoByEventId(eventId);
    if (eventDto != null && eventDto.getEventId() != null) {
      List<GameForEventDto> gameForEventDtos = gameForEventMapper
          .getGameForEventsByEventId(eventDto.getEventId());
      if (gameForEventDtos != null && gameForEventDtos.size() > 0) {
        log.info("该ID为{}站比赛的回合轮次数量为：{}", eventDto.getEventId(), gameForEventDtos.size());
        DataFormatUtil.translatePlayerName(gameForEventDtos);
        eventDto.setGameForEventDtoList(gameForEventDtos);
      }
    } else {
      log.info("该ID为{}站比赛无回合轮次信息", eventDto.getEventId());
    }

    return eventDto;
  }


}
